package com.cpi.cornpp.transitcorn.converter;

import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;

import com.cpi.cornpp.transitcorn.dto.TransitCornDTO;
import com.cpi.cornpp.transitcorn.view.TransitCornView;

/**
 * Transit Corn Converter
 * @author Edgar Joao
 *
 */
public class TransitCornConverter {

	
	/**
	 * Transit Corn Converter DTO to View
	 * @param dto
	 * @return
	 */
	public TransitCornView converterTransitCornDtoToView(TransitCornDTO dto){
		NumberFormat numberFormat = NumberFormat.getInstance();
		numberFormat.setMinimumFractionDigits(2);
		numberFormat.setMaximumFractionDigits(2);		
		TransitCornView transitCornView = null;
		transitCornView = new TransitCornView();
		transitCornView.setPoNumber(dto.getPoNumber());		
		transitCornView.setQuantity(numberFormat.format(dto.getQuantity()));
		transitCornView.setPlace(dto.getPlace());
		return transitCornView;
	}
	
	/**
	 * Transit Corn Converter List DTO to View
	 * @param plantDTOs
	 * @return
	 */
	public List convertDTOs(List transitCornListView){
		List transitCornListViews = null;
		transitCornListViews = new ArrayList(0);
		
		if(!CollectionUtils.isEmpty(transitCornListView)){
			Iterator iterator = transitCornListView.iterator();
			TransitCornDTO e = null;
			
			while(iterator.hasNext()){
				e = (TransitCornDTO) iterator.next();
				transitCornListViews.add(converterTransitCornDtoToView(e));
			}
		}
		return transitCornListViews;
	}

}
